home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Diamond Collection
/
The Diamond Collection (Software Vault)(Digital Impact).ISO
/
cdr43
/
tickets.zip
/
LOTTERY.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1995-03-31
|
25KB
|
540 lines
PROGRAM Scratch_Tickets;
USES crt, uppecase;
TYPE
Ticket = RECORD
Name : String[20];
Cost : Byte;
Winnings : Integer;
Tickets_Bought : Integer;
END;
Ticket_Array = Array[1..800] of Ticket;
VAR
Lottery : Ticket_Array;
ScratchFile : Text;
ch : Char;
Prog_Done, TicketMatch : Boolean;
x, a, count, TempBought, TempWinnings, b, TempCost : Integer;
TempName : String[20];
S : String;
TotalTickets, TotalWinnings, TotalSpent : Integer;
BEGIN
REPEAT
TotalSpent := 0;
TotalTickets := 0;
TotalWinnings := 0;
Prog_Done := false;
Assign (ScratchFile, 'lottery.dat');
{$I-}
reset (ScratchFile);
{$I+}
IF IOResult <> 0 THEN
BEGIN
rewrite (ScratchFile);
close (ScratchFile);
reset (ScratchFile);
END;
x := 0;
count := 0;
WHILE not EOF(ScratchFile) DO
BEGIN
x := x + 1;
count := count + 1;
Readln (ScratchFile, Lottery[x].Name);
Readln (ScratchFile, Lottery[x].Cost);
Readln (ScratchFile, Lottery[x].Winnings);
Readln (ScratchFile, Lottery[x].Tickets_Bought);
TotalTickets := TotalTickets + Lottery[x].Tickets_Bought;
TotalWinnings := TotalWinnings + Lottery[x].Winnings;
TotalSpent := TotalSpent + (Lottery[x].Cost * Lottery[x].Tickets_Bought);
END;
Close (ScratchFile);
CLRSCR;
GOTOXY (1, 8);
WRITELN (' ':21, '*************************************');
WRITELN (' ':21, '* *');
WRITELN (' ':21, '* A) Enter Stats *');
WRITELN (' ':21, '* B) Review $1 Tickets *');
WRITELN (' ':21, '* C) Review $2 Tickets *');
WRITELN (' ':21, '* D) Review $5 Tickets *');
WRITELN (' ':21, '* E) Review ALL *');
WRITELN (' ':21, '* F) Exit *');
WRITELN (' ':21, '* *');
WRITELN (' ':21, '*************************************');
WRITELN;
WRITE (' ':21, ' Make Selection: ');
REPEAT
ch := ReadKey
UNTIL (ch = 'a') or (ch = 'A') or (ch = 'b') or (ch = 'B') or (ch = 'c') or
(ch = 'C') or (ch = 'd') or (ch = 'D') or (ch = 'e') or (ch = 'E') or
(ch = 'F') or (ch = 'f');
IF (Ch = 'A') or (ch = 'a') THEN
BEGIN
CLRSCR;
WRITE ('What''s the Ticket''s name? ');
readln (TempName);
TempName := UpperCase (TempName);
FOR a := 1 to x DO
IF (Lottery[a].Name = TempName) THEN
BEGIN
TicketMatch := true;
write ('How many tickets did you buy? ');
readln (TempBought);
write ('How much did you win? ');
readln (TempWinnings);
Lottery[a].Tickets_Bought := Lottery[a].Tickets_Bought + TempBought;
Lottery[a].Winnings := Lottery[a].Winnings + TempWinnings;
END;
IF not TicketMatch THEN
BEGIN
Write ('Is this a new ticket? (Y/N) ');
REPEAT
ch := readkey;
UNTIL (ch = 'Y') or (ch = 'y') or (ch = 'n') or (ch = 'N');
IF (ch = 'y') or (ch = 'Y') THEN
BEGIN
writeln;
Lottery[x+1].Name := TempName;
WRITE ('How much does the ticket cost? (1/2/5) ');
readln (Lottery[x+1].Cost);
WRITE ('How many tickets did you buy? ');
readln (Lottery[x+1].Tickets_Bought);
WRITE ('How much did you win? ');
readln (Lottery[x+1].Winnings);
count := count + 1;
END;
END;
rewrite (ScratchFile);
FOR x := 1 to count DO
BEGIN
writeln (ScratchFile, Lottery[x].Name);
writeln (ScratchFile, Lottery[x].Cost);
writeln (ScratchFile, Lottery[x].Winnings);
writeln (ScratchFile, Lottery[x].Tickets_Bought);
END;
close (ScratchFile);
END
ELSE IF (ch = 'B') or (ch = 'b') THEN
BEGIN
CLRSCR;
WRITELN ('Ticket Cost Winnings Tickets Bought AVG/Ticket AVG/$1');
writeln ('------------------------------------------------------------------------------');
FOR a := 1 to count DO
IF (Lottery[a].Cost = 1) THEN
BEGIN
WRITE (Lottery[a].Name, ' ':27-length(lottery[a].name));
WRITE (Lottery[a].Cost);
Write (' ':9);
write (lottery[a].winnings);
Str (Lottery[a].Winnings, S);
write (' ':(10 - length(S)));
write (lottery[a].Tickets_Bought);
Str (Lottery[a].Tickets_Bought, S);
write (' ':(14 - length(S)));
write ((lottery[a].winnings / lottery[a].tickets_bought):5:3);
writeln (' ':7, (lottery[a].winnings / (lottery[a].tickets_bought * lottery[a].cost)):5:3);
END;
writeln;
writeln ('Press Enter...');
readln;
END
ELSE IF (ch = 'C') or (ch = 'c') THEN
BEGIN
CLRSCR;
WRITELN ('Ticket Cost Winnings Tickets Bought AVG/Ticket AVG/$1');
writeln ('------------------------------------------------------------------------------');
FOR a := 1 to count DO
IF (Lottery[a].Cost = 2) THEN
BEGIN
WRITE (Lottery[a].Name, ' ':27-length(lottery[a].name));
WRITE (Lottery[a].Cost);
Write (' ':9);
write (lottery[a].winnings);
Str (Lottery[a].Winnings, S);
write (' ':(10 - length(S)));
write (lottery[a].Tickets_Bought);
Str (Lottery[a].Tickets_Bought, S);
write (' ':(14 - length(S)));
write ((lottery[a].winnings / lottery[a].tickets_bought):5:3);
writeln (' ':7, (lottery[a].winnings / (lottery[a].tickets_bought * lottery[a].cost)):5:3);
END;
writeln;
write ('Press Enter...');
readln;
END
ELSE IF (ch = 'D') or (ch = 'd') THEN
BEGIN
CLRSCR;
WRITELN ('Ticket Cost Winnings Tickets Bought AVG/Ticket AVG/$1');
writeln ('------------------------------------------------------------------------------');
FOR a := 1 to count DO
IF (Lottery[a].Cost = 5) THEN
BEGIN
WRITE (Lottery[a].Name, ' ':27-length(lottery[a].name));
WRITE (Lottery[a].Cost);
Write (' ':9);
write (lottery[a].winnings);
Str (Lottery[a].Winnings, S);
write (' ':(10 - length(S)));
write (lottery[a].Tickets_Bought);
Str (Lottery[a].Tickets_Bought, S);
write (' ':(14 - length(S)));
write ((lottery[a].winnings / lottery[a].tickets_bought):5:3);
writeln (' ':7, (lottery[a].winnings / (lottery[a].tickets_bought * lottery[a].cost)):5:3);
END;
writeln;
write ('Press Enter...');
readln;
END
ELSE IF (ch = 'E') or (ch = 'e') THEN
BEGIN
CLRSCR;
GOTOXY (1, 8);
WRITELN (' ':21, '*************************************');
WRITELN (' ':21, '* *');
WRITELN (' ':21, '* A) By Name *');
WRITELN (' ':21, '* B) By Cost *');
WRITELN (' ':21, '* C) By Winnings *');
WRITELN (' ':21, '* D) By Tickets Bought *');
WRITELN (' ':21, '* E) By Average / Ticket *');
WRITELN (' ':21, '* F) By Average / $1 *');
WRITELN (' ':21, '* *');
WRITELN (' ':21, '*************************************');
WRITELN;
WRITE (' ':21, ' Make Selection: ');
REPEAT
ch := ReadKey
UNTIL (ch = 'a') or (ch = 'A') or (ch = 'b') or (ch = 'B') or (ch = 'c') or
(ch = 'C') or (ch = 'd') or (ch = 'D') or (ch = 'e') or (ch = 'E') or
(ch = 'F') or (ch = 'f');
IF (ch = 'a') or (ch = 'A') THEN
BEGIN
CLRSCR;
FOR a := 1 to count DO
FOR b := 1 to (count - 1) DO
IF (Lottery[b].Name > Lottery[b+1].Name) THEN
BEGIN
TempName := Lottery[b].Name;
TempCost := Lottery[b].Cost;
TempWinnings := Lottery[b].Winnings;
TempBought := Lottery[b].Tickets_Bought;
Lottery[b].Name := Lottery[b+1].Name;
Lottery[b].Cost := Lottery[b+1].Cost;
Lottery[b].Winnings := Lottery[b+1].Winnings;
Lottery[b].Tickets_Bought := Lottery[b+1].Tickets_Bought;
Lottery[b+1].Name := TempName;
Lottery[b+1].Cost := TempCost;
Lottery[b+1].Winnings := TempWinnings;
Lottery[b+1].Tickets_Bought := TempBought;
END;
WRITELN ('Ticket Cost Winnings Tickets Bought AVG/Ticket AVG/$1');
writeln ('------------------------------------------------------------------------------');
FOR a := 1 to count do
BEGIN
WRITE (Lottery[a].Name, ' ':27-length(lottery[a].name));
WRITE (Lottery[a].Cost);
Write (' ':9);
write (lottery[a].winnings);
Str (Lottery[a].Winnings, S);
write (' ':(10 - length(S)));
write (lottery[a].Tickets_Bought);
Str (Lottery[a].Tickets_Bought, S);
write (' ':(14 - length(S)));
write ((lottery[a].winnings / lottery[a].tickets_bought):5:3);
writeln (' ':7, (lottery[a].winnings / (lottery[a].tickets_bought * lottery[a].cost)):5:3);
END;
writeln;
writeln ('Press Enter...');
readln;
CLRSCR;
writeln ('Total Tickets Bought = ', TotalTickets);
writeln ('Total Spent = ', TotalSpent);
writeln ('Total Winnings = ', TotalWinnings);
writeln ('Net Difference = ', (TotalWinnings - TotalSpent));
IF (TotalTickets <> 0) AND (TotalSpent <> 0) THEN
BEGIN
writeln ('Overall Average Per Ticket = ', (TotalWinnings/TotalTickets):5:3);
writeln ('Overall Average Per $1 = ', (TotalWinnings/TotalSpent):5:3);
END;
writeln;
write ('Press Enter...');
readln;
END
ELSE IF (ch = 'b') or (ch = 'B') THEN
BEGIN
CLRSCR;
FOR a := 1 to count DO
FOR b := 1 to (count - 1) DO
IF (Lottery[b].Cost > Lottery[b+1].Cost) THEN
BEGIN
TempName := Lottery[b].Name;
TempCost := Lottery[b].Cost;
TempWinnings := Lottery[b].Winnings;
TempBought := Lottery[b].Tickets_Bought;
Lottery[b].Name := Lottery[b+1].Name;
Lottery[b].Cost := Lottery[b+1].Cost;
Lottery[b].Winnings := Lottery[b+1].Winnings;
Lottery[b].Tickets_Bought := Lottery[b+1].Tickets_Bought;
Lottery[b+1].Name := TempName;
Lottery[b+1].Cost := TempCost;
Lottery[b+1].Winnings := TempWinnings;
Lottery[b+1].Tickets_Bought := TempBought;
END;
WRITELN ('Ticket Cost Winnings Tickets Bought AVG/Ticket AVG/$1');
writeln ('------------------------------------------------------------------------------');
FOR a := 1 to count do
BEGIN
WRITE (Lottery[a].Name, ' ':27-length(lottery[a].name));
WRITE (Lottery[a].Cost);
Write (' ':9);
write (lottery[a].winnings);
Str (Lottery[a].Winnings, S);
write (' ':(10 - length(S)));
write (lottery[a].Tickets_Bought);
Str (Lottery[a].Tickets_Bought, S);
write (' ':(14 - length(S)));
write ((lottery[a].winnings / lottery[a].tickets_bought):5:3);
writeln (' ':7, (lottery[a].winnings / (lottery[a].tickets_bought * lottery[a].cost)):5:3);
END;
writeln;
writeln ('Press Enter...');
readln;
CLRSCR;
writeln ('Total Tickets Bought = ', TotalTickets);
writeln ('Total Spent = ', TotalSpent);
writeln ('Total Winnings = ', TotalWinnings);
writeln ('Net Difference = ', (TotalWinnings - TotalSpent));
IF (TotalTickets <> 0) AND (TotalSpent <> 0) THEN
BEGIN
writeln ('Overall Average Per Ticket = ', (TotalWinnings/TotalTickets):5:3);
writeln ('Overall Average Per $1 = ', (TotalWinnings/TotalSpent):5:3);
END;
writeln;
write ('Press Enter...');
readln;
END
ELSE IF (ch = 'C') or (ch = 'c') THEN
BEGIN
CLRSCR;
FOR a := 1 to count DO
FOR b := 1 to (count - 1) DO
IF (Lottery[b].Winnings < Lottery[b+1].Winnings) THEN
BEGIN
TempName := Lottery[b].Name;
TempCost := Lottery[b].Cost;
TempWinnings := Lottery[b].Winnings;
TempBought := Lottery[b].Tickets_Bought;
Lottery[b].Name := Lottery[b+1].Name;
Lottery[b].Cost := Lottery[b+1].Cost;
Lottery[b].Winnings := Lottery[b+1].Winnings;
Lottery[b].Tickets_Bought := Lottery[b+1].Tickets_Bought;
Lottery[b+1].Name := TempName;
Lottery[b+1].Cost := TempCost;
Lottery[b+1].Winnings := TempWinnings;
Lottery[b+1].Tickets_Bought := TempBought;
END;
WRITELN ('Ticket Cost Winnings Tickets Bought AVG/Ticket AVG/$1');
writeln ('------------------------------------------------------------------------------');
FOR a := 1 to count do
BEGIN
WRITE (Lottery[a].Name, ' ':27-length(lottery[a].name));
WRITE (Lottery[a].Cost);
Write (' ':9);
write (lottery[a].winnings);
Str (Lottery[a].Winnings, S);
write (' ':(10 - length(S)));
write (lottery[a].Tickets_Bought);
Str (Lottery[a].Tickets_Bought, S);
write (' ':(14 - length(S)));
write ((lottery[a].winnings / lottery[a].tickets_bought):5:3);
writeln (' ':7, (lottery[a].winnings / (lottery[a].tickets_bought * lottery[a].cost)):5:3);
END;
writeln;
writeln ('Press Enter...');
readln;
CLRSCR;
writeln ('Total Tickets Bought = ', TotalTickets);
writeln ('Total Spent = ', TotalSpent);
writeln ('Total Winnings = ', TotalWinnings);
writeln ('Net Difference = ', (TotalWinnings - TotalSpent));
IF (TotalTickets <> 0) AND (TotalSpent <> 0) THEN
BEGIN
writeln ('Overall Average Per Ticket = ', (TotalWinnings/TotalTickets):5:3);
writeln ('Overall Average Per $1 = ', (TotalWinnings/TotalSpent):5:3);
END;
writeln;
write ('Press Enter...');
readln;
END
ELSE IF (ch = 'd') or (ch = 'D') THEN
BEGIN
CLRSCR;
FOR a := 1 to count DO
FOR b := 1 to (count - 1) DO
IF (Lottery[b].Tickets_Bought < Lottery[b+1].Tickets_Bought) THEN
BEGIN
TempName := Lottery[b].Name;
TempCost := Lottery[b].Cost;
TempWinnings := Lottery[b].Winnings;
TempBought := Lottery[b].Tickets_Bought;
Lottery[b].Name := Lottery[b+1].Name;
Lottery[b].Cost := Lottery[b+1].Cost;
Lottery[b].Winnings := Lottery[b+1].Winnings;
Lottery[b].Tickets_Bought := Lottery[b+1].Tickets_Bought;
Lottery[b+1].Name := TempName;
Lottery[b+1].Cost := TempCost;
Lottery[b+1].Winnings := TempWinnings;
Lottery[b+1].Tickets_Bought := TempBought;
END;
WRITELN ('Ticket Cost Winnings Tickets Bought AVG/Ticket AVG/$1');
writeln ('------------------------------------------------------------------------------');
FOR a := 1 to count do
BEGIN
WRITE (Lottery[a].Name, ' ':27-length(lottery[a].name));
WRITE (Lottery[a].Cost);
Write (' ':9);
write (lottery[a].winnings);
Str (Lottery[a].Winnings, S);
write (' ':(10 - length(S)));
write (lottery[a].Tickets_Bought);
Str (Lottery[a].Tickets_Bought, S);
write (' ':(14 - length(S)));
write ((lottery[a].winnings / lottery[a].tickets_bought):5:3);
writeln (' ':7, (lottery[a].winnings / (lottery[a].tickets_bought * lottery[a].cost)):5:3);
END;
writeln;
writeln ('Press Enter...');
readln;
CLRSCR;
writeln ('Total Tickets Bought = ', TotalTickets);
writeln ('Total Spent = ', TotalSpent);
writeln ('Total Winnings = ', TotalWinnings);
writeln ('Net Difference = ', (TotalWinnings - TotalSpent));
IF (TotalTickets <> 0) AND (TotalSpent <> 0) THEN
BEGIN
writeln ('Overall Average Per Ticket = ', (TotalWinnings/TotalTickets):5:3);
writeln ('Overall Average Per $1 = ', (TotalWinnings/TotalSpent):5:3);
END;
writeln;
write ('Press Enter...');
readln;
END
ELSE IF (ch = 'e') or (ch = 'E') THEN
BEGIN
CLRSCR;
FOR a := 1 to count DO
FOR b := 1 to (count - 1) DO
IF ((Lottery[b].Winnings/Lottery[b].Tickets_Bought) < (Lottery[b+1].Winnings/Lottery[b+1].Tickets_Bought)) THEN
BEGIN
TempName := Lottery[b].Name;
TempCost := Lottery[b].Cost;
TempWinnings := Lottery[b].Winnings;
TempBought := Lottery[b].Tickets_Bought;
Lottery[b].Name := Lottery[b+1].Name;
Lottery[b].Cost := Lottery[b+1].Cost;
Lottery[b].Winnings := Lottery[b+1].Winnings;
Lottery[b].Tickets_Bought := Lottery[b+1].Tickets_Bought;
Lottery[b+1].Name := TempName;
Lottery[b+1].Cost := TempCost;
Lottery[b+1].Winnings := TempWinnings;
Lottery[b+1].Tickets_Bought := TempBought;
END;
WRITELN ('Ticket Cost Winnings Tickets Bought AVG/Ticket AVG/$1');
writeln ('------------------------------------------------------------------------------');
FOR a := 1 to count do
BEGIN
WRITE (Lottery[a].Name, ' ':27-length(lottery[a].name));
WRITE (Lottery[a].Cost);
Write (' ':9);
write (lottery[a].winnings);
Str (Lottery[a].Winnings, S);
write (' ':(10 - length(S)));
write (lottery[a].Tickets_Bought);
Str (Lottery[a].Tickets_Bought, S);
write (' ':(14 - length(S)));
write ((lottery[a].winnings / lottery[a].tickets_bought):5:3);
writeln (' ':7, (lottery[a].winnings / (lottery[a].tickets_bought * lottery[a].cost)):5:3);
END;
writeln;
writeln ('Press Enter...');
readln;
CLRSCR;
writeln ('Total Tickets Bought = ', TotalTickets);
writeln ('Total Spent = ', TotalSpent);
writeln ('Total Winnings = ', TotalWinnings);
writeln ('Net Difference = ', (TotalWinnings - TotalSpent));
IF (TotalTickets <> 0) AND (TotalSpent <> 0) THEN
BEGIN
writeln ('Overall Average Per Ticket = ', (TotalWinnings/TotalTickets):5:3);
writeln ('Overall Average Per $1 = ', (TotalWinnings/TotalSpent):5:3);
END;
writeln;
write ('Press Enter...');
readln;
END
ELSE IF (ch = 'f') or (ch = 'F') THEN
BEGIN
CLRSCR;
FOR a := 1 to count DO
FOR b := 1 to (count - 1) DO
IF ((Lottery[b].Winnings/(Lottery[b].Tickets_Bought*Lottery[b].Cost)) <
(Lottery[b+1].Winnings/(Lottery[b+1].Tickets_Bought*Lottery[b+1].Cost))) THEN
BEGIN
TempName := Lottery[b].Name;
TempCost := Lottery[b].Cost;
TempWinnings := Lottery[b].Winnings;
TempBought := Lottery[b].Tickets_Bought;
Lottery[b].Name := Lottery[b+1].Name;
Lottery[b].Cost := Lottery[b+1].Cost;
Lottery[b].Winnings := Lottery[b+1].Winnings;
Lottery[b].Tickets_Bought := Lottery[b+1].Tickets_Bought;
Lottery[b+1].Name := TempName;
Lottery[b+1].Cost := TempCost;
Lottery[b+1].Winnings := TempWinnings;
Lottery[b+1].Tickets_Bought := TempBought;
END;
WRITELN ('Ticket Cost Winnings Tickets Bought AVG/Ticket AVG/$1');
writeln ('------------------------------------------------------------------------------');
FOR a := 1 to count do
BEGIN
WRITE (Lottery[a].Name, ' ':27-length(lottery[a].name));
WRITE (Lottery[a].Cost);
Write (' ':9);
write (lottery[a].winnings);
Str (Lottery[a].Winnings, S);
write (' ':(10 - length(S)));
write (lottery[a].Tickets_Bought);
Str (Lottery[a].Tickets_Bought, S);
write (' ':(14 - length(S)));
write ((lottery[a].winnings / lottery[a].tickets_bought):5:3);
writeln (' ':7, (lottery[a].winnings / (lottery[a].tickets_bought * lottery[a].cost)):5:3);
END;
writeln;
writeln ('Press Enter...');
readln;
CLRSCR;
writeln ('Total Tickets Bought = ', TotalTickets);
writeln ('Total Spent = ', TotalSpent);
writeln ('Total Winnings = ', TotalWinnings);
writeln ('Net Difference = ', (TotalWinnings - TotalSpent));
IF (TotalTickets <> 0) AND (TotalSpent <> 0) THEN
BEGIN
writeln ('Overall Average Per Ticket = ', (TotalWinnings/TotalTickets):5:3);
writeln ('Overall Average Per $1 = ', (TotalWinnings/TotalSpent):5:3);
END;
writeln;
write ('Press Enter...');
readln;
END;
END
ELSE IF (ch = 'F') or (ch = 'f') THEN
BEGIN
CLRSCR;
WRITELN ('Hope you hit BIG!');
Halt;
END;
UNTIL Prog_Done;
END.